package com.allen.retrofit2_rxjava2.fragment;

import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.allen.retrofit2_rxjava2.R;
import com.allen.retrofit2_rxjava2.base.BaseFragment;
import com.ieyelf.service.service.user.UserData;

import java.lang.ref.WeakReference;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * RecylceView
 * Created by zhazb on 2017/6/12.
 */

public class RecylceFragment extends BaseFragment {


    private MyHandler myHandler = new MyHandler(this);
    private final static int REFRESH_USER_DATA = 1000;

    @Override
    public View getView(LayoutInflater inflater, ViewGroup parent) {
        return inflater.inflate(R.layout.fragment_recylceview, parent, false);
    }

    @Override
    public void init(View view) {

    }

    @Override
    public void data() {

    }

    private static class MyHandler extends Handler {
        private final WeakReference<RecylceFragment> mainActivityReference;

        public MyHandler(RecylceFragment activity) {
            mainActivityReference = new WeakReference<RecylceFragment>(activity);
        }

        @Override
        public void handleMessage(Message msg) {
            RecylceFragment curActivity = mainActivityReference.get();
            if (curActivity != null) {
                switch (msg.what) {
                    case SHOW_TOAST:
                        curActivity.showToast(msg.obj.toString());
                        break;
                    case REFRESH_USER_DATA:
                        UserData userData = (UserData) msg.obj;

                        break;
                    default:
                        break;
                }
            }
        }
    }



//    @OnClick(value = {})
//    private void onClick(View view) {
//        switch (view.getId()) {
//
//        }
//    }


    private void sendMessage(int what, Object object) {
        Message message = myHandler.obtainMessage();
        message.what = what;
        message.obj = object;
        message.sendToTarget();
    }


    @Override
    public void onResume() {
        super.onResume();
    }

}
